package com.ygl.provider.controller;

import com.ygl.api.ServiceProviderApi;
import com.ygl.api.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

/**
 * @Author yanggld
 * @Date 2019/11/21-10:11
 * @Description
 */
@Slf4j
@RefreshScope
@RestController
public class TestController implements ServiceProviderApi {

	@Value("/test/${name}")
	private String name;

	@Value("/test/${server.port}")
	private String port;

	@GetMapping("/test/name")
	public Object getName(){
		log.info("name----------->{}",name);
		return name+":"+port;
	}

	@Override
	public String findName(@RequestHeader String token) {
		ServletRequestAttributes requestAttributes = (ServletRequestAttributes)RequestContextHolder.getRequestAttributes();
		String uid = requestAttributes.getRequest().getHeader("uid");
		return "nike"+token+uid;
	}

	@Override
	public User findUser(User user) {
		return user;
	}
}
